﻿using AutoMapper;
using Flurl.Util;
using LF.Application.Extend;
using LF.Common;
using LF.Domain;
using LF.Domain.Entities;
using LF.Shared.Dtos.Out;
using System.Runtime.InteropServices;
using Volo.Abp.AutoMapper;
using E = LF.Domain.Entities;
using I = LF.Shared.Dtos.Input;
using O = LF.Shared.Dtos.Out;
using T = LF.Domain.TargetModel;

namespace LF.Application
{

    public class LFProfile : Profile
    {
        public LFProfile()
        {

            CreateMap<I.AppDicInput, E.AppDic>()
                .IgnoreAllNonExisting();

            CreateMap<E.User, O.UserOut>()
              .IgnoreAllNonExisting();
            CreateMap<O.UserOut, E.User>()
             .IgnoreAllNonExisting();
            CreateMap<E.UserRole, O.UserRoleOut>()
             .IgnoreAllNonExisting();
            CreateMap<O.UserRoleOut, E.UserRole>()
             .IgnoreAllNonExisting();


            CreateMap<E.Role, O.RoleOut>()
              .IgnoreAllNonExisting();
            CreateMap<O.RoleOut, E.Role>()
                .IgnoreAllNonExisting();
            CreateMap<E.RoleMenu, O.RoleMenuOut>()
              .IgnoreAllNonExisting();
            CreateMap<O.RoleMenuOut, E.RoleMenu>()
                .IgnoreAllNonExisting();


            CreateMap<E.AppDic, O.AppDicOut>();


            CreateMap<E.Rule, I.RuleInput>()
                .IgnoreAllNonExisting();
            CreateMap<E.Rule, O.RuleOut>()
                .IgnoreAllNonExisting();

            CreateMap<I.RuleInput, E.Rule>()
                .IgnoreAllNonExisting();

   

            CreateMap<E.Notice, O.NoticeOut>();
            CreateMap<O.NoticeOut, E.Notice>()
              .IgnoreAllNonExisting();


            CreateMap<E.China, O.ChinaOut>()
            .IgnoreAllNonExisting();
            CreateMap<O.ChinaOut, E.China>()
            .IgnoreAllNonExisting();
            // 添加物料相关映射
            CreateMap<E.Material, O.MaterialOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.MaterialOut, E.Material>()
                .IgnoreAllNonExisting();
            CreateMap<I.MaterialInput, E.Material>()
                .IgnoreAllNonExisting();
            CreateMap<E.Material, I.MaterialInput>()
                .IgnoreAllNonExisting();
            CreateMap<O.MaterialOut, I.MaterialInput>()
                .IgnoreAllNonExisting();
            CreateMap< I.MaterialInput, O.MaterialOut>()
                .IgnoreAllNonExisting();


            // 添加物料分类映射 (暂时注释，等编译后解除注释)
            CreateMap<E.MaterialCategory, O.MaterialCategoryOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.MaterialCategoryOut, E.MaterialCategory>()
                .IgnoreAllNonExisting();
            CreateMap<I.MaterialCategoryInput, E.MaterialCategory>()
                .IgnoreAllNonExisting();
            CreateMap<E.MaterialCategory, I.MaterialCategoryInput>()
                .IgnoreAllNonExisting();

            CreateMap<E.Deptment, O.DeptmentOut>().IgnoreAllNonExisting();
            CreateMap<O.DeptmentOut, E.Deptment>().IgnoreAllNonExisting();

            // 添加菜单映射
            CreateMap<E.Menu, O.MenuOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.MenuOut, E.Menu>()
                .IgnoreAllNonExisting();

            CreateMap<E.UserDept, O.UserDeptOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.UserDeptOut, E.UserDept>()
                .IgnoreAllNonExisting();

            // 添加字典类型映射
            CreateMap<E.DictType, O.DictTypeOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.DictTypeOut, E.DictType>()
                .IgnoreAllNonExisting();

            // 添加字典项映射
            CreateMap<E.DictItem, O.DictItemOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.DictItemOut, E.DictItem>()
                .IgnoreAllNonExisting();
         
            // 添加参数配置映射
            CreateMap<E.ParamConfig, O.ParamConfigOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.ParamConfigOut, E.ParamConfig>()
                .IgnoreAllNonExisting();
                
            // 添加知识库映射
            CreateMap<E.KnowledgeBase, O.KnowledgeBaseOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.KnowledgeBaseOut, E.KnowledgeBase>()
                .IgnoreAllNonExisting();
                
            // 添加知识库文件映射
            CreateMap<E.KnowledgeFile, O.KnowledgeFileOut>()
                .IgnoreAllNonExisting();
            CreateMap<O.KnowledgeFileOut, E.KnowledgeFile>()
                .IgnoreAllNonExisting();
                
        }

        public static string GetDic(Guid[] ids)
        {
            var value = DomainConfig.AppDics.Where(p => ids.Contains(p.Id)).Select(p => p.Value);
            if (value != null)
            {
                return string.Join('、', value);
            }
            return string.Empty;
        }
    }
}